﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using DAL;

namespace BLL
{
    public class BComplaint
    {
        private readonly DAL.DComplaint _dComplaint = new DComplaint();
        #region  Method

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return _dComplaint.GetMaxId();
        }

        /// <summary>
        /// 获得黑名单列表
        /// </summary>
        /// <returns></returns>
         public List<string> GetBlackListOfPasseager()
         {
             return _dComplaint.GetBlackListOfPasseager();
         }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return _dComplaint.Exists(id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Model.ComplaintInfo model)
        {
            return _dComplaint.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.ComplaintInfo model)
        {
            return _dComplaint.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            return _dComplaint.Delete(id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            return _dComplaint.DeleteList(idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.ComplaintInfo GetModel(int id)
        {

            return _dComplaint.GetModel(id);
        }

        ///// <summary>
        ///// 得到一个对象实体，从缓存中
        ///// </summary>
        //public Model.ComplaintInfo GetModelByCache(int id)
        //{

        //    string CacheKey = "tcomplaintModel-" + id;
        //    object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
        //    if (objModel == null)
        //    {
        //        try
        //        {
        //            objModel = _dComplaint.GetModel(id);
        //            if (objModel != null)
        //            {
        //                int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
        //                Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
        //            }
        //        }
        //        catch { }
        //    }
        //    return (Model.ComplaintInfo)objModel;
        //}

        /// <summary>
        /// 获得数据列表-司机
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return _dComplaint.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表-乘客
        /// </summary>
        public DataSet GetListOfPasseager(string strWhere)
        {
            return _dComplaint.GetListOfPasseager(strWhere);
        }

        /// <summary>
        /// 获取指定手机号被投诉次数
        /// </summary>
        /// <param name="phoneNumber">手机号</param>
        /// <param name="complaintObject">被投诉对象：0为司机，1为乘客</param>
        /// <returns></returns>
        public int GetRecordCountOfUserInThisMonth(string phoneNumber, int complaintObject)
        {
            return _dComplaint.GetRecordCountOfUserInThisMonth(phoneNumber,complaintObject);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.ComplaintInfo> GetModelList(string strWhere)
        {
            DataSet ds = _dComplaint.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.ComplaintInfo> DataTableToList(DataTable dt)
        {
            List<Model.ComplaintInfo> modelList = new List<Model.ComplaintInfo>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.ComplaintInfo model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.ComplaintInfo();
                    if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["Complaintsobject"] != null && dt.Rows[n]["Complaintsobject"].ToString() != "")
                    {
                        model.Complaintsobject = int.Parse(dt.Rows[n]["Complaintsobject"].ToString());
                    }
                    if (dt.Rows[n]["Complaintreason"] != null && dt.Rows[n]["Complaintreason"].ToString() != "")
                    {
                        model.Complaintreason = dt.Rows[n]["Complaintreason"].ToString();
                    }
                    if (dt.Rows[n]["ComplaintAid"] != null && dt.Rows[n]["ComplaintAid"].ToString() != "")
                    {
                        model.ComplaintAid = dt.Rows[n]["ComplaintAid"].ToString();
                    }
                    if (dt.Rows[n]["ComplaintBid"] != null && dt.Rows[n]["ComplaintBid"].ToString() != "")
                    {
                        model.ComplaintBid = dt.Rows[n]["ComplaintBid"].ToString();
                    }
                    if (dt.Rows[n]["time"] != null && dt.Rows[n]["time"].ToString() != "")
                    {
                        model.time = DateTime.Parse(dt.Rows[n]["time"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return _dComplaint.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return _dComplaint.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return _dComplaint.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}
